package com.lebang.service.buss;

import com.lebang.domain.LbbMemberIsfirstinfo;
import com.lebang.mapper.LbbMemberIsfirstinfoMapper;
import com.lebangweb.common.TextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Auther: szq
 * @Date: 2019-12-14
 * @Description:
 */
@Service
public class MemberIsFirstInfoService {
    @Autowired
    private LbbMemberIsfirstinfoMapper lbbMemberIsfirstinfoMapper;
    public LbbMemberIsfirstinfo selectByid(String memberId) {
        return lbbMemberIsfirstinfoMapper.getInfoById(memberId);
    }

    public void insertByid(LbbMemberIsfirstinfo lbbMemberIsfirstinfo) {

        lbbMemberIsfirstinfoMapper.insert(lbbMemberIsfirstinfo);
    }

    public long checkTime(String memberId) {
        LbbMemberIsfirstinfo memberIsfirstinfo = lbbMemberIsfirstinfoMapper.selectById(memberId);
        if(memberIsfirstinfo == null){
            return 0;
        }
        Date date = new Date();
        if(TextUtil.isEmpty(memberIsfirstinfo.getCreateTime())){
            memberIsfirstinfo.setCreateTime(LocalDateTime.now());
            lbbMemberIsfirstinfoMapper.updateByPrimaryKeySelective(memberIsfirstinfo);
            return Timestamp.valueOf(memberIsfirstinfo.getCreateTime()).getTime() + 86400000 - date.getTime();
        }
        long time = Timestamp.valueOf(memberIsfirstinfo.getCreateTime()).getTime() + 86400000 - date.getTime();
        if (time > 0) {
            return time;
        }
        return 0;
    }
}
